<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
        //race()将多个promise对象实例包装成新的promise对象
        //只有所有状态是fullfilled，最后结果才能执行.then
        //只要有一个状态为rejected，那么最终结果会执行为.reject

        let promise1=new Promise((resolve,reject)=>{
            setTimeout(()=>{
                resolve(1000)
            },1000)
        })
    
        let promise2=new Promise((resolve,reject)=>{
            setTimeout(()=>{
                resolve('hello')
            },1000)
        })
        
        let promise3=new Promise((resolve,reject)=>{
            setTimeout(()=>{
                resolve('hhhh')
            },1000)
        })
        
        let promise4 =Promise.race([promise1,promise2,promise3])
        .then((res)=>{
            console.log(res);
        })
        .catch((err)=>{
            console.log(err);
        })
        
        
        </script>
</body>
</html>